package com.zhuss.repair.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.repair.repair.BackRepairBo;
import com.zhuss.bean.bo.repair.repair.CreateRepairBo;
import com.zhuss.bean.bo.repair.repair.DeleteRepairBo;
import com.zhuss.bean.bo.repair.repairAudit.RepairAuditFanKuiBo;
import com.zhuss.bean.bo.repair.repairAudit.RepairWeiXiuBo;
import com.zhuss.bean.bo.repair.repairPingJia.RepairPingJiaBo;
import com.zhuss.bean.vo.repair.repair.DetailRepairVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.enums.RepairEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.repair.db.dao.ext.RepairAuditDao;
import com.zhuss.repair.db.dao.ext.RepairDao;
import com.zhuss.repair.db.dao.ext.RepairOverDao;
import com.zhuss.repair.db.dao.ext.RepairPingJiaDao;
import com.zhuss.repair.db.entity.Repair;
import com.zhuss.repair.db.entity.RepairAudit;
import com.zhuss.repair.db.entity.RepairOver;
import com.zhuss.repair.db.entity.RepairPingjia;
import com.zhuss.util.JsonUtil;

/**
 * 删除餐品 processor
 * @Author: zhushanshuo
 * @Date: 2020/02/28 16:01
 */
@Component("repairPingJia")
public class RepairPingJia extends AbstractProcessor<Object, RepairPingJiaBo> implements Processor<Object, RepairPingJiaBo> {

    @Autowired
    private RepairPingJiaDao repairPingJiaDao;

    @Autowired
    private RepairAuditDao repairAuditDao;
    /**
     * 校验
     */
	@Override
	@SuppressWarnings("unchecked")
    public void check(RepairPingJiaBo bo) throws WpsException {
    	/*Long repairId = bo.getRepairId();
    	List<Long> permissionIdList = (List<Long>) repairPermissionRead.listPermissionId(repairId);
    	if (!permissionIdList.isEmpty()) {
    		throw new WpsException(ExceptionCode.不能删除已绑定权限的餐品);
    	}
    	List<Long> userIdList = (List<Long>) userRepairRead.listUserId(repairId);
    	if (!userIdList.isEmpty()) {
    		throw new WpsException(ExceptionCode.不能删除已绑定用户的餐品);
    	}*/
    }
    
    /**
     * 操作方法(反馈)
     */
    @Override
    public Object process(RepairPingJiaBo param) throws WpsException {
    	//反馈表添加记录数据
    	RepairPingjia repairPingjia= new RepairPingjia();
    	repairPingjia.setRepair_id(param.getRepair_id());
    	repairPingjia.setDeal_user_id(param.getDeal_user_id());//param.getConcurrentUserId()
    	repairPingjia.setContent(param.getContent());
    	repairPingJiaDao.insertRepairPingJia(repairPingjia);
    	
    	
    	//更新主表流程状态
    	RepairAudit repairAudit = new  RepairAudit();
    	repairAudit.setRepair_id(param.getRepair_id());
    	repairAudit.setStep(RepairEnum.维修评价完成.getStep());
    	repairAudit.setAudit(RepairEnum.维修评价完成.getAudit());
    	repairAuditDao.updateRepairStatus(repairAudit);
    	
        return null;
    }
    
    

    
    /**
     * 操作日志
     */
	@Override
	public Object log(RepairPingJiaBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.维修评价.key());
    	record.setAction(LogActionEnum.维修评价.key());
    	/*record.setTargetId(param.getRepairId().longValue());*/
    	/*record.setTargetName(param.getRemark());*/
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
